#include "main.h"
#include "ec11.h"
#include <stdio.h>
static uint8_t EC11_flag = 0;
static uint8_t CW_1 = 0;
static uint8_t CW_2 = 0;  

void EC11_callback(void)
{   
    // 只要处理一个脚的外部中断--上升沿&下降沿
    GPIO_PinState alv = HAL_GPIO_ReadPin(GPIOA,GPIO_PIN_6);
    GPIO_PinState blv = HAL_GPIO_ReadPin(GPIOA,GPIO_PIN_4);

    if(EC11_flag == 0 && alv == GPIO_PIN_RESET)
    {
        CW_1 = blv;
        EC11_flag = 1;
    }

    if(EC11_flag && alv)
    {
        CW_2 = !blv;//取反是因为 alv,blv必然异步，一高一低。
        if(CW_1&&CW_2)
        {
            printf("right on\n");
        }
        if(CW_1 == 0 && CW_2 == 0)
        {
            printf("left on\n");
        }
        EC11_flag = 0;
    }
}
